﻿//-----------------------------------------------------------------------
// <copyright file="DataRecievedEventArgs.cs" company="FastNET Services">
//     Copyright (c) 2008-2009. All Rights Reserved.
// </copyright>
// <license>
//     GPLv2
// </license>
// <warranty>
//     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
//     BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
//     NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
//     DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//     OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// </warranty>
//-----------------------------------------------------------------------
#region Usings

using System;
using GateShift.Common.Networking.Enumerations;
using GateShift.Common.Networking.Structures;

#endregion

namespace GateShift.Common.Networking.Events
{
    /// <summary>
    /// General class for data being recieved
    /// </summary>
    public class DataRecievedEventArgs
        : EventArgs
    {
        /// <summary>
        /// Initializes a new instance of the DataRecievedEventArgs class
        /// </summary>
        /// <param name="primaryCode">PrimaryCode from the packet</param>
        /// <param name="secondaryCode">SecondaryCode from the packet</param>
        /// <param name="data">Data that was sent</param>
        /// <param name="wasEncrypted">Whether or not the data was sent in an encrypted manner</param>
        public DataRecievedEventArgs(byte primaryCode, byte secondaryCode, byte[] data, bool wasEncrypted)
        {
            PrimaryCode = primaryCode;
            SecondaryCode = secondaryCode;
            Data = data;
            WasEncrypted = wasEncrypted;
        }

        /// <summary>
        /// Initializes a new instance of the DataRecievedEventArgs class
        /// </summary>
        /// <param name="packet">DataPacket to pull information from</param>
        /// <remarks>Internals Shared only to Client Networking and Server Networking</remarks>
        internal DataRecievedEventArgs(DataPacket packet)
        {
            PrimaryCode = packet.PrimaryCode;
            SecondaryCode = packet.SecondaryCode;
            Data = packet.Data;
            WasEncrypted = (packet.Flags & DataPacketFlags.Encrypted) == DataPacketFlags.Encrypted;
        }

        /// <summary>
        /// Gets the primary identification code
        /// </summary>
        public byte PrimaryCode { get; private set; }

        /// <summary>
        /// Gets the secondary identification code
        /// </summary>
        public byte SecondaryCode { get; private set; }

        /// <summary>
        /// Gets the data that was transmitted
        /// </summary>
        public byte[] Data { get; private set; }

        /// <summary>
        /// Gets a value indicating whether or not the data was sent in an encrypted manner
        /// </summary>
        public bool WasEncrypted { get; private set; }
    }
}